package com.hardy.job;

import java.util.ArrayList;

import static com.hardy.leetcode.EvenReversal.printArray;
import static com.hardy.leetcode.EvenReversal.swap;


/**
 * @author fuxiaohui3@nuoyuan.com.cn
 * @date 2018/11/21 16:06
 * 字符串的排列
 */
public class StringPailie {
    public ArrayList<String> Permutation(String str) {
        ArrayList<String> res = new ArrayList();
        if (str != null && str.length() > 0) {
            process(str.toCharArray(), 0, res);
        }
        return res;
    }

    private void process(char str[], int i, ArrayList<String> res) {
        if (i == str.length - 1) {
            String value = String.valueOf(str);
            if (!res.contains(value)) {
                res.add(value);
            }
        } else {
            for (int j = i; j < str.length; j++) {
                swap(str, i, j);
                process(str, i + 1, res);
                swap(str, i, j);
            }
        }
    }
}
